﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LPrisaMVC.Entities;
using System.Data;
using Microsoft.Practices.Unity;

namespace LPrisaMVC.DAO
{
    public class PagoDAO:MasterRepository, IPagoDAO
    {
        public List<DETALLEPAGO> GetAllFromPagos()
        {
            var query = from p in Context.DETALLEPAGOes.Include("CREDITO")
                        orderby p.Fecha descending
                        select p;
            return query.ToList();
        }

        public List<DETALLEPAGO> GetFromPagobyClienteOfCredito(string cliente)
        {
            throw new NotImplementedException();
        }

        public List<DETALLEPAGO> GetFromPagosbyCreditoId(int creditoId)
        {
            var query = from c in Context.DETALLEPAGOes
                        where c.CreditoId.Equals(creditoId)
                        select c;
            return query.ToList();
        }

        public List<DETALLEPAGO> GetFromPagobyFecha(DateTime? fec1, DateTime? fec2)
        {
            throw new NotImplementedException();
        }

        public DETALLEPAGO GetFromPagoById(int id)
        {
            var query = from p in Context.DETALLEPAGOes
                        where p.Id.Equals(id)
                        select p;
            return query.SingleOrDefault();
        }

        public void AddPago(DETALLEPAGO pago)
        {
            Context.DETALLEPAGOes.Add(pago);
            Context.SaveChanges();
        }

        public void UpdatePago(DETALLEPAGO pago)
        {
            Context.Entry(pago).State = EntityState.Modified;
            Context.SaveChanges();
        }

        public void CancelarPago(int id)
        {
            var existe = Context.DETALLEPAGOes.Find(id);
            Context.DETALLEPAGOes.Remove(existe);
            Context.SaveChanges();
        }

        
    }
}
